package domain;

public class Question {
	//domain实体  存储文件中的题目  增强可读性
	private String title;
	private String answer;
	private String picture;//存储图片路径
	public Question() {
	}
	public Question(String title, String answer) {
		this.title = title;
		this.answer = answer;
	}
	public Question(String title, String answer,String picture) {
		this.title = title;
		this.answer = answer;
		this.picture = picture;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getAnswer() {
		return answer;
	}
	public void setAnswer(String answer) {
		this.answer = answer;
	}
	
	//重写Quesition类中的equals和hashCode方法
	//想要将Question对象存入HashSet集合中  让set集合帮我们去掉重复元素
	public boolean equals(Object obj) {
		if(this==obj) {
			return true;
		}
		if(obj instanceof Question) {
			Question anotherQuestion = (Question)obj;
			String thisTitle = this.title.substring(0,this.title.indexOf("<br>"));
			String anotherTitle = anotherQuestion.title.substring(0,anotherQuestion.title.indexOf("<br>"));
			if(thisTitle.equals(anotherTitle)) {
				return true;
			}
		}
		return false;
	}
	@Override
	public int hashCode() {
		String thisTitle = this.title.substring(0,this.title.indexOf("<br>"));
		return thisTitle.hashCode();
	}
}
